      <template>
      <!-- 更新密码表单-->
      <div id="updatepasswordForm">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item>
            <h1 style="font-size:30px;color:#00B38A">拉勾</h1>
          </el-form-item>
            <el-form-item label="当前密码" prop="oldPwd" style="width:500px">
                <el-input v-model="ruleForm.oldPwd" clearable size="small" type="password"></el-input>
              </el-form-item>
             <el-form-item label="新密码" prop="newPwd">
                <el-input v-model="ruleForm.newPwd" clearable size="small" type="password"></el-input>
              </el-form-item>
              <el-form-item label="确认密码" prop="confirmPwd">
                <el-input v-model="ruleForm.confirmPwd" clearable size="small" type="password"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="updatepassword('ruleForm')" class="button">确定</el-button>
                <el-button @click="resetForm('ruleForm')" class="button">重置</el-button>
              </el-form-item>
            </el-form>
        <p></p>
      </div>
      </template>
      <script>
      export default {
      name: "demo1",
      data() {
    var validatePass = (rule, value, callback) => {
        if (value === '') {
                callback(new Error('请输入密码'));
        } else if(value !== this.userDTO.content.password) {
           //   callback(this.userDTO.password)
              callback(new Error('密码不正确'));
              console.log(this.userDTO.content.password)
        } else {
           if(this.ruleForm.newPwd !== '') {
              this.$refs.ruleForm.validateField('newPwd');
          }
          callback();
          }
      };

     var validatePass2 = (rule, value, callback) => {
        if (value === '') {
                callback(new Error('请输入密码'));
        }  else if (value == this.ruleForm.oldPwd) {
              callback(new Error('新旧密码不能相同!'));
          } 
        else {
          if (this.ruleForm.confirmPwd !== '') {
              this.$refs.ruleForm.validateField('confirmPwd');
          }
          callback();
        }
      };
      var validatePass3 = (rule, value, callback) => {
          if (value === '') {
              callback(new Error('请再次输入密码'));
          } else if (value !== this.ruleForm.newPwd) {
              callback(new Error('两次输入密码不一致!'));
          } else {
              callback();
          }
      };


 
    return {
       ruleForm: {
          oldPwd: '',
          newPwd: '',
          confirmPwd:''
        },

       rules: {
         oldPwd: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { validator: validatePass, trigger: 'blur' }
          ],
          newPwd: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { validator: validatePass2, trigger: 'blur' }
          ],
          confirmPwd:[
            { required: true, message: '请确认密码', trigger: 'blur' },
           // { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' },
            { validator: validatePass3, trigger: 'blur', required: true }
          ],
        },
      isLogin: false, // 登录状态，true：已登录，false：未登录
      userDTO:null, // 用来保存登录的用户信息
      isHasNewMessage: false, // 是否有新的推送消息
      phone: "", // 双向绑定表单 手机号
      password: "",
      userid: "", // 双向绑定表单 密码
      x:null
    };
  },
  computed: {
  },
  watch: {
  },
  mounted() {
  },
  created(){
     this.userDTO = JSON.parse( localStorage.getItem("user") );
    if(this.userDTO != null){
        this.isLogin = true; // 已登录
    }else{
      // 去检测微信是否登录过
      this.axios
      .get("http://localhost:80/user/checkWxStatus")
      .then( (result)=>{
        this.userDTO = result.data;
        this.phone = this.userDTO.content.phone;
        this.password = this.userDTO.content.password;
     //   this.login();// 走普通登录
      })
      .catch( (error)=>{
       // this.$message.error("请先登录！");
        this.dialogFormVisible2 = true; 
      });
    }
  },
    methods: {
    updatepassword(){ // 前去登录
      return this.axios
      .get("http://localhost:80/user/updatepassword" , {
        params:{
          userid: this.userDTO.content.id,
          password: this.ruleForm.newPwd,
        }
      })
      .then( (result)=>{
        console.log( result );
        this.userDTO = result.data; // 保存返回数据中的用户对象信息
        this.isLogin = true; // 更新登录状态
        localStorage.setItem("user", JSON.stringify(this.userDTO)); 
        console.log(this.userDTO)// 将登录成功的对象信息保存到本地储存中
        console.log(this.userDTO.state)
        if(this.userDTO.state===200)
        {
            　this.$message.success('修改成功') 
             this.$refs.ruleForm.resetFields();
        }
      
      } )
      .catch( (error)=>{
        this.$message.error("登录失败！");
      });
    },
    resetForm(ruleForm)
    {
       this.$refs.ruleForm.resetFields();
    }
    }
};
</script>